package info.empathymobile.forecast.testenv.beans;

import java.util.ArrayList;
import java.util.Date;

import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;

public class TestBaseData {
	
	public static final String CONNECTIVITY_WIFI_DATA = "Connectivity Wi-Fi";
	public static final String CONNECTIVITY_3G_DATA = "Connectivity 3G";
	public static final String BATTERY_DATA = "Battery";
	public static final String[] TEST_BASE_DATA_TYPE_ARRAY = {CONNECTIVITY_WIFI_DATA, CONNECTIVITY_3G_DATA, BATTERY_DATA};
	public static final int MIN_BASE_DATA_LENGHT = 18;
	
	// id is generated by the database and set on the object automagically
	@DatabaseField(generatedId = true)
	private int id;
	@DatabaseField
	private Date baseDataCreatedAt = null;
	@DatabaseField
	private String userUUID = null;
	@DatabaseField
	private int usedThreshold = 0;
	@DatabaseField
	private int usedDaysAgo = 0;
	@DatabaseField
	private String baseDataType = "NONE";
	@DatabaseField(dataType = DataType.SERIALIZABLE)
	private int[] baseData = null;

	public TestBaseData() {
		// needed by ormlite
		this.baseDataCreatedAt = new Date(System.currentTimeMillis());
	}
	
	public TestBaseData(String userUUID, String baseDataType){
		this();
		this.userUUID = userUUID;
		this.baseDataType = baseDataType;
	}

	public TestBaseData(String userUUID, int usedThreshold, int usedDaysAgo, 
			String baseDataType, int[] baseData) {
		this(userUUID, usedThreshold, usedDaysAgo, baseDataType);
		this.baseData = baseData;
	}
	
	public TestBaseData(String userUUID, int usedThreshold, int usedDaysAgo, String baseDataType) {
		this();
		this.userUUID = userUUID;
		this.usedThreshold = usedThreshold;
		this.usedDaysAgo = usedDaysAgo;
		this.baseDataType = baseDataType;
	}

	public TestBaseData(TestBaseData data, ArrayList<Integer> newBaseData) {
		this(data.getUserUUID(), data.getUsedThreshold(), 
				data.getUsedDaysAgo(), data.getBaseDataType());

		this.baseData = new int[newBaseData.size()];
		for (int i = 0; i < newBaseData.size(); i++) {
			this.baseData[i] = newBaseData.get(i);
		}
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public Date getBaseDataCreatedAt() {
		return baseDataCreatedAt;
	}

	public void setBaseDataCreatedAt(Date baseDataCreatedAt) {
		this.baseDataCreatedAt = baseDataCreatedAt;
	}

	public String getUserUUID() {
		return userUUID;
	}

	public void setUserUUID(String userUUID) {
		this.userUUID = userUUID;
	}

	public int getUsedThreshold() {
		return usedThreshold;
	}

	public void setUsedThreshold(int usedThreshold) {
		this.usedThreshold = usedThreshold;
	}

	public int getUsedDaysAgo() {
		return usedDaysAgo;
	}

	public void setUsedDaysAgo(int usedDaysAgo) {
		this.usedDaysAgo = usedDaysAgo;
	}

	public String getBaseDataType() {
		return baseDataType;
	}
	
	public void setBaseDataType(String baseDataType) {
		this.baseDataType = baseDataType;
	}

	public int[] getBaseData() {
		return baseData;
	}

	public void setBaseData(int[] baseData) {
		this.baseData = baseData;
	}

	public static int indexOfTestBaseDataType(String type) {
		for (int i = 0; i < TEST_BASE_DATA_TYPE_ARRAY.length; i++) {
			if(type.equals(TEST_BASE_DATA_TYPE_ARRAY[i])){
				return i;
			}
		}
		return -1;
	}
	
	@Override
	public String toString() {
		return userUUID 
				+ " | " + baseDataType
				+ " | " + usedThreshold
				+ " | " + usedDaysAgo
				+ " | " + baseDataCreatedAt
				+ " | " + baseData.length;
	}
}
